package com.outfood.utils;

import com.outfood.service.IStoreService;
import com.rys.common.utils.StringUtils;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import javax.annotation.Resource;

/**
 * @Author huisonglin
 * @Description
 * @PackageName outfoodcat-master
 * @Package com.outfood.utils
 * @Date 2024-06-26 17:16
 * @Version 1.0
 */
@Component
public class RedisUtil {
    

    @Resource
    IStoreService storeService;


    public static String COOKIE = "COOKIE:";

    public static String STORAGE = "STORAGE:";

    public void addCookie(Long storeId,String cookies){
        Jedis jedis = new Jedis();
        jedis.set(COOKIE+storeId+"",cookies);
    }
    public void addStorage(Long storeId,String cookies){
        Jedis jedis = new Jedis();
        jedis.set(STORAGE+storeId+"",cookies);
    }

    public String getCookie(Long storeId){
        Jedis jedis = new Jedis();
        String cookie = jedis.get(COOKIE + storeId);
        if(StringUtils.isBlank(cookie)){
            String elemcookie = storeService.get(storeId).getElemcookie();
            cookie = elemcookie;
        }
        return cookie;
    }

    public String getStorage(Long storeId){
        Jedis jedis = new Jedis();
        String storage = jedis.get(STORAGE + storeId);
        if(StringUtils.isBlank(storage)){
            storage = storeService.get(storeId).getElemstorage();
        }
        return storage;
    }

    public void removeCookie(Long storeId){
        Jedis jedis = new Jedis();
        jedis.del(COOKIE+storeId);
    }

    public void removeStorage(Long storeId){
        Jedis jedis = new Jedis();
        jedis.del(STORAGE+storeId);
    }

}
